
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/base/PageProvideNode.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/helper/ImageHelper.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/helper/RouteHelper.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/view/main/mine/MineVM.dart';

import 'VideoFocusWidget.dart';
import 'VideoRecommendedWidget.dart';
import 'VideoVM.dart';



class CreationWidget extends PageProvideNode {

  CreationWidget() : super(VideoVM());

  @override
  Widget buildContent(BuildContext context) {
    print("object CreationWidget");
    return Creation();
  }
}


//我的
class Creation extends StatefulWidget  {

  @override
  _CreationState createState() => _CreationState();
}

class _CreationState extends State<Creation> with TickerProviderStateMixin{

  late TabController _tabController;
  late PageController _pageController;
  late MineVM mineVM;
  ValueNotifier<int> cartValueNotifier= ValueNotifier(0);
  List<Widget> _list = [VideoFocusWidget(), VideoRecommendedWidget(),];

  @override
  void initState() {
    super.initState();
    mineVM=MineVM();
    _tabController=TabController(length: 2, vsync: this,initialIndex: 1);
    _pageController=PageController(initialPage: 1);
    WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
      mineVM.getMyInfoData(isDialog:false,requestDone: (){
        cartValueNotifier.value=mineVM.mineBean?.cartQuantity??0;
        cartValueNotifier.notifyListeners();
      });
    });
  }

  @override
  void dispose() {
    super.dispose();
    _tabController.dispose();
    cartValueNotifier.dispose();
  }

  @override
  Widget build(BuildContext context) {
    var top = ScreenUtil().statusBarHeight;
    var width = MediaQuery.of(context).size.width;
    return Container(
      alignment: Alignment.topCenter,
      child: Stack(
        children: [
          PageView(
              controller: _pageController,
              onPageChanged: (index){
                _tabController.animateTo(index);
              },
              children: _list
          ),
          Container(
            padding: EdgeInsets.fromLTRB(16.w,  top+12.h, 16.w, 10.h),
            height: 100.h,
            alignment: Alignment.center,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                InkWell(onTap:(){
                  toLoginWidget(context);
                },child: Image.asset(assetPath("ic_find_main_live.png"),height: 19.r,fit: BoxFit.fitHeight)),
                Expanded(
                  child: Container(
                    alignment: Alignment.center,
                    padding: EdgeInsets.fromLTRB(width/8, 0, width/8, 0),
                    child: TabBar(
                        controller: _tabController,
                        indicatorColor:Colors.white ,
                        indicatorWeight: 2.w,
                        // indicator:BoxDecoration(border: BorderDirectional(top:BorderSide() ),color:Colors.white,borderRadius: BorderRadius.all(Radius.circular(1.w))) ,
                        indicatorSize: TabBarIndicatorSize.label,
                        labelColor: Colors.white,
                        onTap: (index){
                          _pageController.animateToPage(index, duration: Duration(milliseconds: 250), curve: Curves.ease);
                        },
                        labelStyle: TextStyle(fontSize: 20.sp),
                        unselectedLabelColor: Colors.white,
                        tabs: [
                          Tab(child: Text("关注"),),
                          Tab(child: Text("推荐"),),
                        ]),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
